/*
   Mr. Smith
   Made By ups2000ups
   GMS Like
*/
/*
	info
	int [] _temp				= {x, x      , x      , x    , x    , x};
	int [] _tempinfo			= {x, x      , x      , x    , x    , x};

	int [] _temp				= {Number_Of_Items(rigt now 2), ID/Money};
	int [] _tempinfo			= {AlwaysZero     , x};
	
	if x = 0 it is mesos
	if x = 999 you will earn that item (can't earn more than 1 right now example you can't get 10 tree branches)
	if x = something_else the amounth of a item you will lose

	if you don't get it don't use it :)
*/

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	int type = npc.getSelected();
	npc.setVariable("type", type);

	// material
	string [] menu 		= {"Make a glove", "Upgrade a glove", "Create material"};

	int [] _ProcessedWood_v1 	= {4003001, 4000003};
	int [] _ProcessedWood_v1info 	= {1      , 10};

	int [] _ProcessedWood_v2 	= {4003001, 4000018};
	int [] _ProcessedWood_v2info 	= {1      , 5};
	
	int [] _Screws			= {4003000, 4011001, 4011000};
	int [] _Screwsinfo		= {15     , 1      , 1};


	int [] _temp				= {0,0,0,0,0,0,0,0};
	int [] _tempinfo			= {0,0,0,0,0,0,0,0};

	//Make Glove
	int [] make		= {10, 1082003, 1082000, 1082004, 1082001, 1082007, 1082008, 1082023, 1082009, 1082059};
	string [] makeinfo	= {"empty", "(level limit : 10, warrior)", "(level limit : 15, warrior)", "(level limit : 20, warrior)", "(level limit : 25, warrior)", "(level limit : 30, warrior)", "(level limit : 35, warrior)", "(level limit : 40, warrior)", "(level limit : 50, warrior)", "(level limit : 60, warrior)"};


	int [] _Juno				= {5, 4000021, 4011001, 1000, 1082003};
	int [] _Junoinfo			= {0, 15     , 1      ,    0, 999};

	int [] _SteelFingerlessGloves		= {4, 4011001, 2000, 1082000};
	int [] _SteelFingerlessGlovesinfo	= {0, 2      ,    0, 999};

	int [] _Venon				= {5, 4000021, 4011000, 5000, 1082004};
	int [] _Venoninfo			= {0, 40     , 2      ,    0, 999};

	int [] _WhiteFingerlessGloves		= {4, 4011002, 10000, 1082001};
	int [] _WhiteFingerlessGlovesinfo	= {0, 2      ,     0, 999};

	int [] _BronzeMisselc			= {6, 4011000, 4011001, 4003000, 20000, 1082007};
	int [] _BronzeMisselinfoc		= {0, 3      , 2      , 15     , 0    , 999};

	int [] _SteelBriggon			= {6, 4000021, 4011001, 4003000, 30000, 1082008};
	int [] _SteelBriggoninfo		= {0, 30     , 4      , 30     , 0    , 999};

	int [] _IronKnuckle			= {6, 4000021, 4011001, 4003000, 40000, 1082023};
	int [] _IronKnuckleinfo			= {0, 50     , 5      , 40     , 0    , 999};

	int [] _SteelBrist			= {7, 4011001, 4021007, 4000030, 4003000, 50000, 1082009};
	int [] _SteelBristinfo			= {0, 3      , 2      , 30     , 45     , 0    , 999};

	int [] _BronzeClench			= {8, 4011007, 4011000, 4011006, 4000030, 4003000, 70000, 1082059};
	int [] _BronzeClenchinfo		= {0, 1      , 8      , 6      , 50     , 50     ,0    , 999};


	// Uppgrade
	int [] upgrade		= {11, 1082005, 1082006, 1082035, 1082036, 1082024, 1082025, 1082010, 1082011, 1082060, 1082061};
	string [] upgradeinfo	= {"empty", "(level limit : 30, warrior)", "(level limit : 30, warrior)", "(level limit : 35, warrior)", "(level limit : 35, warrior)", "(level limit : 40, warrior)", "(level limit : 40, warrior)", "(level limit : 50, warrior)", "(level limit : 50, warrior)", "(level limit : 60, warrior)", "(level limit : 60, warrior)"};

	int [] _BronzeMissel 			= {5, 1082007, 4011001, 20000, 1082005};
	int [] _BronzeMisselinfo 		= {0, 1      , 1      , 0    , 999};
	int [] _OrihalconMissel 		= {5, 1082007, 4011005, 25000, 1082006};
	int [] _OrihalconMisselinfo 		= {0, 1      , 2      , 0    , 999};


	int [] _YellowBriggon 			= {5, 1082008, 4021006, 30000, 1082035};
	int [] _YellowBriggoninfo 		= {0, 1      , 3      , 0    , 999};
	int [] _DarkBriggon 			= {5, 1082008, 4021008, 40000, 1082036};
	int [] _DarkBriggoninfo 		= {0, 1      , 1      , 0    , 999};

	int [] _AdamantiumKnuckle		= {5, 1082023, 4011003, 45000, 1082024};
	int [] _AdamantiumKnuckleinfo 		= {0, 1      , 4      , 0    , 999};
	int [] _DarkKnuckle 			= {5, 1082023, 4021008, 50000, 1082025};
	int [] _DarkKnuckleinfo 		= {0, 1      , 2      , 0    , 999};

	int [] _MithrilBrist			= {5, 1082009, 4011002, 55000, 1082010};
	int [] _MithrilBristinfo 		= {0, 1      , 5      , 0    , 999};
	int [] _GoldBrist 			= {5, 1082009, 4011006, 60000, 1082011};
	int [] _GoldBristinfo 			= {0, 1      , 4      , 0    , 999};

	int [] _SapphireClench			= {6, 1082059, 4011002, 4021005, 70000, 1082060};
	int [] _SapphireClenchinfo 		= {0, 1      , 3      , 5      , 0    , 999};
	int [] _DarkClench			= {6, 1082059, 4021007, 4021008, 80000, 1082061};
	int [] _DarkClenchinfo 			= {0, 1      , 2      , 2      , 0    , 999};

//4000021 - Leather
//4000030 - Dragon Skin
//4003000 - Screw

//4011000 - Bronze Plate
//4011001 - Steel Plate
//4011002 - Mithril Plate
//4011003 - Adamantium Plate
//4011004 - Silver Plate
//4011005 - Orihalcon Plate
//4011006 - Gold Plate
//4011007 - Moon Rock

//4021000 - Garnet
//4021001 - Amethyst
//4021002 - AquaMarine
//4021003 - Emerald
//4021004 - Opal
//4021005 - Sapphire
//4021006 - Topaz
//4021007 - Diamond
//4021008 - Black Crystal
//4021009 - Star Rock

	if(state == 0){
		npc.addText("I am Mr. Thunder's apprentice. He's getting up there with age, and he isn't what he used to be... Haha, oh crap, please don't tell him that I said that... Anyway... I can make various items specifically designed for warriors, so what do you think? Wanna leave it up to me?");
		npc.sendYesNo();
	}
	else if(state == 1){

		if(npc.getSelected() == YES) {
			npc.addText("Alright! The service fee will be reasonable so don't worry about it. What do you want to do?#b\r\n#L0#" + menu[0] + "#l\r\n#L1#" + menu[1] + "#l\r\n#L2#" + menu[2] + "#l#k");
			npc.sendSimple();

		}
		else if(npc.getSelected() == NO){
			npc.addText("Sigh... I'll definitely hear it from my boss if I don't make the norm today... Oh well, that sucks.");
			npc.sendNext();
			npc.end();
		}

	}
	else if(state == 2){
		if(type== 0){
			npc.addText("I'm the best glove-maker in this town!! Now... what kind of a glove do you want to make?");
			for(int x = 1; x < make[0]; x++){
				npc.addText("#b\r\n#L" + (x-1) + "##t" + make[x] + "##k " + makeinfo[x] + "#l");
			}
			npc.setState(19);
			npc.sendSimple();
		}

		else if(type== 1){
			npc.addText("So you want to upgrade the glove? OK, then. A word of warning, though: All the items that will be used for upgrading will be gone, but if you use an item that has been #rupgraded#k with a scroll, the effect will disappear when upgraded. Please take that into consideration when making the decision, OK?");
			npc.setState(9);
			npc.sendNext();

		}

		else if(type== 2){
			npc.addText("So you want to make some materials, huh? Okay... what kind of material do you want to make?");
			npc.addText("#b\r\n#L0#Make #t" + _ProcessedWood_v1[0] + "# with #t" + _ProcessedWood_v1[1] + "##l\r\n#L1#Make #t" + _ProcessedWood_v2[0] + "# with #t" + _ProcessedWood_v2[1] + "##l\r\n#L2#Make #t" + _Screws[0] + "##l#k");
			npc.sendSimple();
		}
	}

//----------------------------------------------- Make Item
	else if(state == 20){
		npc.setGetSaveInt(type);
		if(npc.getSaveInt() == 0){
			_temp = _Juno;
			_tempinfo = _Junoinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _SteelFingerlessGloves;
			_tempinfo = _SteelFingerlessGlovesinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _Venon;
			_tempinfo = _Venoninfo;
		}
		else if(npc.getSaveInt() == 3){
			_temp = _WhiteFingerlessGloves;
			_tempinfo = _WhiteFingerlessGlovesinfo;
		}
		else if(npc.getSaveInt() == 4){
			_temp = _BronzeMisselc;
			_tempinfo = _BronzeMisselinfoc;
		}
		else if(npc.getSaveInt() == 5){
			_temp = _SteelBriggon;
			_tempinfo = _SteelBriggoninfo;
		}
		else if(npc.getSaveInt() == 6){
			_temp = _IronKnuckle;
			_tempinfo = _IronKnuckleinfo;
		}
		else if(npc.getSaveInt() == 7){
			_temp = _SteelBrist;
			_tempinfo = _SteelBristinfo;
		}
		else if(npc.getSaveInt() == 8){
			_temp = _BronzeClench;
			_tempinfo = _BronzeClenchinfo;
		}

		npc.addText("To make one #t" +  _temp[_temp[0]-1] + "#, I need the following items. " + makeinfo[npc.getSaveInt()+1] + " and please make sure you don't use an item that's been upgraded as a material for it. What do you think? Do you want one?");


		for(int i = 1; i < _temp[0]; i++){
			if(_tempinfo[i] == 0){
				npc.addText("#b\r\n#v4031138# " + _temp[i] + " Mesos #k");
			}
			else if(_tempinfo[i] == 999){
				// nothing right now just to not show is as payment
			}
			else if(_tempinfo[i] > 1){
				npc.addText("#b\r\n#v" + _temp[i] + "# " + + _tempinfo[i] + " #t" + _temp[i] + "##k");
			}
			else {
				npc.addText("#b\r\n#v" + _temp[i] + "#  #t" + _temp[i] + "##k");
			}
		} 
		npc.sendYesNo();
	}

	else if(state == 21){

		if(npc.getSaveInt() == 0){ // added again same reason as always
			_temp = _Juno;
			_tempinfo = _Junoinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _SteelFingerlessGloves;
			_tempinfo = _SteelFingerlessGlovesinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _Venon;
			_tempinfo = _Venoninfo;
		}
		else if(npc.getSaveInt() == 3){
			_temp = _WhiteFingerlessGloves;
			_tempinfo = _WhiteFingerlessGlovesinfo;
		}
		else if(npc.getSaveInt() == 4){
			_temp = _BronzeMisselc;
			_tempinfo = _BronzeMisselinfoc;
		}
		else if(npc.getSaveInt() == 5){
			_temp = _SteelBriggon;
			_tempinfo = _SteelBriggoninfo;
		}
		else if(npc.getSaveInt() == 6){
			_temp = _IronKnuckle;
			_tempinfo = _IronKnuckleinfo;
		}
		else if(npc.getSaveInt() == 7){
			_temp = _SteelBrist;
			_tempinfo = _SteelBristinfo;
		}
		else if(npc.getSaveInt() == 8){
			_temp = _BronzeClench;
			_tempinfo = _BronzeClenchinfo;
		}


		if(npc.getSelected() == YES){

			type = 0;

			for(int x = 1; x < _temp[0]; x++){

				if(_tempinfo[x] == 0){
					if(player.getMesos() < _temp[x]){
						type = 1;
					}
				}
				else if(_tempinfo[x] == 999){
					// nothing just to skip it for now
				}
				else {
					if(player.getItemAmount(_temp[x]) < _tempinfo[x]){
						type = 1;
					}
				}
			}

			if(type == 0){
				for(int x = 1; x < _temp[0]; x++){

					if(_tempinfo[x] == 0){
						player.giveMesos(-_temp[x]);
					}
					else if(_tempinfo[x] == 999){
						player.giveItem(_temp[x], 1);
					}
					else {
						player.giveItem(_temp[x], -_tempinfo[x]);
					}
				}

				npc.addText("Did it turn out OK? Well it looks like it did! Come back if you want to create something else.");
				npc.sendNext();
				npc.end();
			}
			else if (type == 1){
				npc.addText("Check and see if you have everything you need and if your equipment inventory may be full or not.");
				npc.sendNext();
				npc.end();
			}

		}
		else if(npc.getSelected() == NO){
			npc.addText("Lacking the materials? It's OK... Collect them all and then come find me, alright? I'll be waiting...");
			npc.sendNext();
			npc.end();
		}
	}


// ---------------------------------------------- Upgrade
	else if(state == 10){
		npc.addText("So ~~ What kind of a glove do you want to upgrade and create?");
		for(int x = 1; x < upgrade[0]; x++){
			npc.addText("#b\r\n#L" + (x-1) + "##t" + upgrade[x] + "##k " + upgradeinfo[x] + "#l");
		}
		npc.sendSimple();
	}
	else if(state == 11){
		npc.setGetSaveInt(type);

		if(npc.getSaveInt() == 0){
			_temp = _BronzeMissel;
			_tempinfo = _BronzeMisselinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _OrihalconMissel;
			_tempinfo = _OrihalconMisselinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _YellowBriggon;
			_tempinfo = _YellowBriggoninfo;
		}
		else if(npc.getSaveInt() == 3){
			_temp = _DarkBriggon;
			_tempinfo = _DarkBriggoninfo;
		}
		else if(npc.getSaveInt() == 4){
			_temp = _AdamantiumKnuckle;
			_tempinfo = _AdamantiumKnuckleinfo;
		}
		else if(npc.getSaveInt() == 5){
			_temp = _DarkKnuckle;
			_tempinfo = _DarkKnuckleinfo;
		}
		else if(npc.getSaveInt() == 6){
			_temp = _MithrilBrist;
			_tempinfo = _MithrilBristinfo;
		}
		else if(npc.getSaveInt() == 7){
			_temp = _GoldBrist;
			_tempinfo = _GoldBristinfo;
		}
		else if(npc.getSaveInt() == 8){
			_temp = _SapphireClench;
			_tempinfo = _SapphireClenchinfo;
		}
		else if(npc.getSaveInt() == 9){
			_temp = _DarkClench;
			_tempinfo = _DarkClenchinfo;
		}

		npc.addText("To make one #t" +  _temp[_temp[0]-1] + "#, I need the following items. " + upgradeinfo[npc.getSaveInt()+1] + " and please make sure you don't use an item that's been upgraded as a material for it. What do you think? Do you want one?");


		for(int i = 1; i < _temp[0]; i++){
			if(_tempinfo[i] == 0){
				npc.addText("#b\r\n#v4031138# " + _temp[i] + " Mesos #k");
			}
			else if(_tempinfo[i] == 999){
				// nothing right now just to not show is as payment
			}
			else if(_tempinfo[i] > 1){
				npc.addText("#b\r\n#v" + _temp[i] + "# " + + _tempinfo[i] + " #t" + _temp[i] + "##k");
			}
			else {
				npc.addText("#b\r\n#v" + _temp[i] + "#  #t" + _temp[i] + "##k");
			}
		} 
		npc.sendYesNo();
	}

	else if(state == 12){

		if(npc.getSaveInt() == 0){ // ------------ added again like always since angelscript sux :D
			_temp = _BronzeMissel;
			_tempinfo = _BronzeMisselinfo;
		}
		else if(npc.getSaveInt() == 1){
			_temp = _OrihalconMissel;
			_tempinfo = _OrihalconMisselinfo;
		}
		else if(npc.getSaveInt() == 2){
			_temp = _YellowBriggon;
			_tempinfo = _YellowBriggoninfo;
		}
		else if(npc.getSaveInt() == 3){
			_temp = _DarkBriggon;
			_tempinfo = _DarkBriggoninfo;
		}
		else if(npc.getSaveInt() == 4){
			_temp = _AdamantiumKnuckle;
			_tempinfo = _AdamantiumKnuckleinfo;
		}
		else if(npc.getSaveInt() == 5){
			_temp = _DarkKnuckle;
			_tempinfo = _DarkKnuckleinfo;
		}
		else if(npc.getSaveInt() == 6){
			_temp = _MithrilBrist;
			_tempinfo = _MithrilBristinfo;
		}
		else if(npc.getSaveInt() == 7){
			_temp = _GoldBrist;
			_tempinfo = _GoldBristinfo;
		}
		else if(npc.getSaveInt() == 8){
			_temp = _SapphireClench;
			_tempinfo = _SapphireClenchinfo;
		}
		else if(npc.getSaveInt() == 9){
			_temp = _DarkClench;
			_tempinfo = _DarkClenchinfo;
		}


		if(npc.getSelected() == YES){

			type = 0;

			for(int x = 1; x < _temp[0]; x++){

				if(_tempinfo[x] == 0){
					if(player.getMesos() < _temp[x]){
						type = 1;
					}
				}
				else if(_tempinfo[x] == 999){
					// nothing just to skip it for now
				}
				else {
					if(player.getItemAmount(_temp[x]) < _tempinfo[x]){
						type = 1;
					}
				}
			}

			if(type == 0){
				for(int x = 1; x < _temp[0]; x++){

					if(_tempinfo[x] == 0){
						player.giveMesos(-_temp[x]);
					}
					else if(_tempinfo[x] == 999){
						player.giveItem(_temp[x], 1);
					}
					else {
						player.giveItem(_temp[x], -_tempinfo[x]);
					}
				}

				npc.addText("Did it turn out OK? Well it looks like it did! Come back if you want to upgrade something else.");
				npc.sendNext();
				npc.end();
			}
			else if (type == 1){
				npc.addText("Check and see if you have everything you need and if your equipment inventory may be full or not.");
				npc.sendNext();
				npc.end();
			}
		}
		else if(npc.getSelected() == NO){
			npc.addText("Lacking the materials? It's OK... Collect them all and then come find me, alright? I'll be waiting...");
			npc.sendNext();
			npc.end();
		}
	}

// ------------------------------------------ Materials

	else if(state == 3){
		npc.setGetSaveInt(type);


		if(npc.getSaveInt() == 0){
			npc.addText("With #b10 #t" + _ProcessedWood_v1[1] + "##k, I can make 1 #t" + _ProcessedWood_v1[0] + "#(s). Be thankful, because this one's pn me- What do you think? How many do you want?");
			npc.sendGetNumber(0, 0, 100);
		}
		else if(npc.getSaveInt() == 1){
			npc.addText("With #b5 #t" + _ProcessedWood_v2[1] + "##k, I can make 1 #t" + _ProcessedWood_v2[0] + "#(s). Be thankful, because this one's pn me- What do you think? How many do you want?");
			npc.sendGetNumber(0, 0, 100);
		}
		else if(npc.getSaveInt() == 2){
			npc.addText("With #b1 #t" + _Screws[1] + "#(s) and #t" + _Screws[2] + "#(s) each #k, I can make 15 #t" + _Screws[0] + "#(s). Be thankful, because this one's pn me- What do you think? How many do you want?");
			npc.sendGetNumber(0, 0, 100);	
		}
	}
	else if(state == 4){

		if(npc.getSaveInt() == 0){
			npc.addText("You want to make #b#t" + _ProcessedWood_v1[0] + "#(s)#k " + npc.getNumber() + "time(s)? I'll need #r" + _ProcessedWood_v1info[1]*npc.getNumber() + " #t" + _ProcessedWood_v1[1] + "##k then.");
			npc.sendYesNo(); 
		}
		else if(npc.getSaveInt() == 1){
			npc.addText("You want to make #b#t" + _ProcessedWood_v2[0] + "#(s)#k " + npc.getNumber() + "time(s)? I'll need #r" + _ProcessedWood_v2info[1]*npc.getNumber() + " #t" + _ProcessedWood_v2[1] + "##k then.");
			npc.sendYesNo();
		}
		else if(npc.getSaveInt() == 2){
			npc.addText("You want to make #b#t" + _Screws[0] + "##k " + npc.getNumber() + "time(s)? I'll need #r" + _Screwsinfo[1]*npc.getNumber() + " #t" + _Screws[1] + "# and #t" + _Screws[2] + "#(s)#k then.");
			npc.sendYesNo();

		}
	}
	else if(state == 5){
		if(npc.getSelected() == YES){
			if(npc.getSaveInt() == 0){
				if(player.getItemAmount(_ProcessedWood_v1[1]) >= 10*npc.getNumber()){
					player.giveItem(_ProcessedWood_v1[1], -(10*npc.getNumber()));
					player.giveItem(_ProcessedWood_v1[0], 1*npc.getNumber());
					npc.addText("Here! Take " + npc.getNumber() + " #t" + _ProcessedWood_v1[0] + "#(s). Don't you think i'm as good as Mr. Thunder? You'll be more than satisfied with what I made here.");
					npc.sendNext();
					npc.end();
				}
				else {
					npc.addText("Check and see if you have everything you need and if your ETC inventory may be full or not.");
					npc.sendNext();
					npc.end();
				}
			}
			else if(npc.getSaveInt() == 1){
				if(player.getItemAmount(_ProcessedWood_v2[1]) >= 5*npc.getNumber()){
					player.giveItem(_ProcessedWood_v2[1], -(5*npc.getNumber()));
					player.giveItem(_ProcessedWood_v2[0], 1*npc.getNumber());
					npc.addText("Here! Take " + npc.getNumber() + " #t" + _ProcessedWood_v2[0] + "#(s). Don't you think i'm as good as Mr. Thunder? You'll be more than satisfied with what I made here.");
					npc.sendNext();
					npc.end();
				}
				else {
					npc.addText("Check and see if you have everything you need and if your ETC inventory may be full or not.");
					npc.sendNext();
				}	
			}
			else if(npc.getSaveInt() == 2){
				if((player.getItemAmount(_Screws[1]) >= 1*npc.getNumber()) && (player.getItemAmount(_Screws[2]) >= 1*npc.getNumber())){
					player.giveItem(_Screws[2], -(1*npc.getNumber()));
					player.giveItem(_Screws[1], -(1*npc.getNumber()));
					player.giveItem(_Screws[0], 15*npc.getNumber());
					npc.addText("Here! Rake " + npc.getNumber() + " #t" + _Screws[0] + "#(s). Don't you think i'm as good as Mr. Thunder? You'll be more than satisfied with what I made here.");
					npc.sendNext();
					npc.end();
				}
				else {
					npc.addText("Check and see if you have everything you need and if your ETC inventory may be full or not.");
					npc.sendNext();
				}
			}
		}
		else if(npc.getSelected() == NO){
			npc.addText("Lacking the materials? It's all good... Collect them all and then come find me, alright? I'll be waiting...");
			npc.sendNext();
			npc.end();
		}
	}
}